@extends('admin.common.base-master')

@section('html-head')
{{--    <script src="{{url('js/lib/distpicker.data.js')}}" type="text/javascript"></script>--}}
{{--    <script src="{{url("js/lib/distpicker.js")}}" type="text/javascript"></script>--}}
@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <em></em>
            <a href="#">模板地区列表</a>
        </div>
        @include('admin.common.express-header')

        <div class="filter-box clearfix">
            <div class="fr">
                <a class="addBtn" href="javascript:;" onclick="upPop(0,'','','','','','')">新增</a>
            </div>
        </div>

        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>配送区域</th>
                    <th>首重（kg）</th>
                    <th>首重运费（元）</th>
                    <th>续重（kg）</th>
                    <th>续重运费（元）</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($fees) > 0)
                    @foreach($fees as $fee)
                        <tr id="fee_{{$fee->id}}">
                            <td>{{$fee->id}}</td>
                            <td>{{$fee->province}}</td>
{{--                            <td>@if($fee->province!='all')--}}
{{--                                    {{$fee->province}} @if($fee->city!='all') {{$fee->city}} @else 全省 @endif--}}
{{--                                @else 无限制 @endif--}}
{{--                            </td>--}}
                            <td>{{$fee->first_weight}}</td>
                            <td>{{$fee->first_price}}</td>
                            <td>{{$fee->next_weight}}</td>
                            <td>{{$fee->next_price}}</td>
                            <td>
                                <a href="javascript:void(0);" data-id="{{$fee->id}}" style="color: #ef1414;"
                                   onclick="upPop('{{$fee->id}}','{{$fee->province}}','{{$fee->city}}','{{$fee->first_weight}}','{{$fee->first_price}}','{{$fee->next_weight}}','{{$fee->next_price}}')">编辑</a>
                                <a href="javascript:void(0);" class="del" data-id="{{$fee->id}}" >删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <?php echo $fees->render(); ?>
    </div>

    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="feeId" id="feeId" value=""/>
            <input type="hidden" name="express_blade_id" id="express_blade_id" value="@if($this_blade){{$this_blade->id}}@endif"/>
            <a class="close-fee" href="javascript:void(0);"></a>
            <h3>模板“@if($this_blade){{$this_blade->name}}@endif”地区设置</h3>

            <div class="fill-list">
                <span class="fill-tit">省份:</span>
                <select tabindex="1" data-placeholder="选择省" id="province" class="span8" style="width: 20%;height: 30px;">
                <option value="全国" data-code="">全国</option>
                <option value="北京市" data-code="110000">北京市</option>
                <option value="天津市" data-code="120000">天津市</option>
                <option value="河北省" data-code="130000">河北省</option>
                <option value="山西省" data-code="140000">山西省</option>
                <option value="内蒙古自治区" data-code="150000">内蒙古自治区</option>
                <option value="辽宁省" data-code="210000">辽宁省</option>
                <option value="吉林省" data-code="220000">吉林省</option>
                <option value="黑龙江省" data-code="230000">黑龙江省</option>
                <option value="上海市" data-code="310000">上海市</option>
                <option value="江苏省" data-code="320000">江苏省</option>
                <option value="浙江省" data-code="330000">浙江省</option>
                <option value="安徽省" data-code="340000">安徽省</option>
                <option value="福建省" data-code="350000">福建省</option>
                <option value="江西省" data-code="360000">江西省</option>
                <option value="山东省" data-code="370000">山东省</option>
                <option value="河南省" data-code="410000">河南省</option>
                <option value="湖北省" data-code="420000">湖北省</option>
                <option value="湖南省" data-code="430000">湖南省</option>
                <option value="广东省" data-code="440000">广东省</option>
                <option value="广西壮族自治区" data-code="450000">广西壮族自治区</option>
                <option value="海南省" data-code="460000">海南省</option>
                <option value="重庆市" data-code="500000">重庆市</option>
                <option value="四川省" data-code="510000">四川省</option>
                <option value="贵州省" data-code="520000">贵州省</option>
                <option value="云南省" data-code="530000">云南省</option>
                <option value="西藏自治区" data-code="540000">西藏自治区</option>
                <option value="陕西省" data-code="610000">陕西省</option>
                <option value="甘肃省" data-code="620000">甘肃省</option>
                <option value="青海省" data-code="630000">青海省</option>
                <option value="宁夏回族自治区" data-code="640000">宁夏回族自治区</option>
                <option value="新疆维吾尔自治区" data-code="650000">新疆维吾尔自治区</option>
                <option value="台湾省" data-code="710000">台湾省</option>
                <option value="香港特别行政区" data-code="810000">香港特别行政区</option>
                <option value="澳门特别行政区" data-code="820000">澳门特别行政区</option>
            </select>
            </div>
{{--            <div class="fill-list" id="distpicker">--}}
{{--                <select tabindex="1" data-placeholder="Select here.." id="province" class="span8" style="width: 20%;height: 30px;">--}}
{{--                    <option value="" selected></option>--}}
{{--                </select> 省/直辖市等--}}
{{--                <span style="display: inline-block;width: 20px"></span>--}}
{{--                <select tabindex="1" data-placeholder="Select here.." id="city" class="span8" style="width: 20%;height: 30px;">--}}
{{--                    <option value="" selected>全部</option>--}}
{{--                </select>市--}}
{{--            </div>--}}

            <div class="fill-list">
                <span class="fill-tit">首重（kg）:</span>
                <input class="fill-ipt" type="text" name="first_weight" id="first_weight" value="">
            </div>
            <div class="fill-list">
                <span class="fill-tit">首重运费（元）:</span>
                <input class="fill-ipt" type="text" name="first_price" id="first_price" value="">
            </div>
            <div class="fill-list">
                <span class="fill-tit">续重（kg）:</span>
                <input class="fill-ipt" type="text" name="next_weight" id="next_weight" value="">
            </div>
            <div class="fill-list">
                <span class="fill-tit">续重运费（元）:</span>
                <input class="fill-ipt" type="text" name="next_price" id="next_price" value="">
            </div>
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="提交">
            </div>
        </div>
    </div>

    <script>
        function upPop(id,pvc,city,fw,fp,nw,np){
            $('#feeId').val(id);
            $('#first_weight').val(fw);
            $('#first_price').val(fp);
            $('#next_weight').val(nw);
            $('#next_price').val(np);
            $('#province').val(pvc);
            // $('#city').val(city);

            $('.upPop-box').upPop();
            //
            // $('#distpicker').distpicker({
            //     province: pvc,
            //     city:city
            // });
        }

        $(function(){


            $(document).on('click', '#subThisForm', function () {

                var first_weight = $('#first_weight').val();
                var first_price = $('#first_price').val();
                var next_weight = $('#next_weight').val();
                var next_price = $('#next_price').val();
                var province = $('#province option:selected').val();
                var city = $('#city option:selected').val();
                var id   = $('#feeId').val();
                var express_blade_id   = $('#express_blade_id').val();
                console.log(first_weight,first_price,next_weight,next_price,province,city);
                $.ajax({
                    url: '{{route("Api.Admin.sys.setExpressCustomFee")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id:id,
                        express_blade_id:express_blade_id,
                        first_weight:first_weight,
                        first_price:first_price,
                        next_weight:next_weight,
                        next_price:next_price,
                        province:province,
                        city:city,
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.sys.delExpressCustomFee')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#fee_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });
    </script>
@endsection